home *** CD-ROM | disk | FTP | other *** search
/ Holt Researcher: American History / Holt Researcher: American History.iso / pc / modules / grphwiz.dxr / 00152_subtable object.ls < prev    next >
Encoding:
Text File  |  2000-01-14  |  6.6 KB  |  269 lines

  1. property _me, pTable, pSuperTable, pTableChannel, pTableLoc, pVSlider, pUpButton, pDownButton, pVisRect
  2. global gGraph
  3.  
  4. on new me, tableName, castName, tableChannel, tableLoc, vSlider, upButton, downButton, descendant
  5.   if objectp(descendant) then
  6.     _me = descendant
  7.   else
  8.     _me = me
  9.   end if
  10.   pTable = member(tableName, castName)
  11.   pTableChannel = tableChannel
  12.   pTableLoc = tableLoc
  13.   pVSlider = vSlider
  14.   pUpButton = upButton
  15.   pDownButton = downButton
  16.   return me
  17. end
  18.  
  19. on setSuperTable me, superTable
  20.   pSuperTable = superTable
  21.   return me
  22. end
  23.  
  24. on init me, cellWidth, cellHeight, numRows, numCols, data, visRect
  25.   sizeAllCells(pTable, cellWidth, cellHeight)
  26.   pTable.rowCount = numRows
  27.   pTable.columnCount = numCols
  28.   pTable.borderSize = 1
  29.   pTable.defaultMacTextFont = "helvetica"
  30.   pTable.defaultWinTextFont = "arial"
  31.   pTable.defaultTextSize = 9
  32.   pTable.defaultHAlign = "center"
  33.   pTable.defaultVAlign = "center"
  34.   pTable.tableData = data
  35.   pVisRect = visRect
  36.   return me
  37. end
  38.  
  39. on condemn me
  40.   _me = 0
  41.   return me
  42. end
  43.  
  44. on Inscope me
  45.   puppetSprite(pTableChannel, 1)
  46.   return me
  47. end
  48.  
  49. on outScope me
  50.   puppetSprite(pTableChannel, 0)
  51.   return me
  52. end
  53.  
  54. on showMe me
  55.   set the loc of sprite pTableChannel to pTableLoc
  56.   updateStage()
  57.   return me
  58. end
  59.  
  60. on hideMe me
  61.   set the loc of sprite pTableChannel to point(-9999, -9999)
  62.   updateStage()
  63.   return me
  64. end
  65.  
  66. on trackMouse me
  67.   return me
  68. end
  69.  
  70. on doRollover me
  71.   return me
  72. end
  73.  
  74. on scrollUp me
  75.   oldTop = pVisRect.top
  76.   pVisRect.top = pVisRect.top + (getSetting(pVSlider) - oldTop)
  77.   pVisRect.bottom = pVisRect.bottom + (getSetting(pVSlider) - oldTop)
  78.   sprite(pTableChannel).vScroll = (getRowHeight(member(pTable), 1) - 1) * (getSetting(pVSlider) - 1)
  79.   return me
  80. end
  81.  
  82. on scrollDown me
  83.   oldTop = pVisRect.top
  84.   pVisRect.top = pVisRect.top + (getSetting(pVSlider) - oldTop)
  85.   pVisRect.bottom = pVisRect.bottom + (getSetting(pVSlider) - oldTop)
  86.   sprite(pTableChannel).vScroll = (getRowHeight(member(pTable), 1) - 1) * (getSetting(pVSlider) - 1)
  87.   return me
  88. end
  89.  
  90. on getTopRow me
  91.   return pVisRect.top
  92. end
  93.  
  94. on getLeftColumn me
  95.   return pVisRect.left
  96. end
  97.  
  98. on getBottomRow me
  99.   return pVisRect.bottom
  100. end
  101.  
  102. on getRightColumn me
  103.   return pVisRect.right
  104. end
  105.  
  106. on atTop me
  107.   return pVisRect.top = 1
  108. end
  109.  
  110. on atBottom me
  111.   return pVisRect.bottom = pTable.rowCount
  112. end
  113.  
  114. on getNumColumns me
  115.   return pTable.columnCount
  116. end
  117.  
  118. on getNumRows me
  119.   return pTable.rowCount
  120. end
  121.  
  122. on isAbove me, v
  123.   return v <= the top of sprite pTableChannel
  124. end
  125.  
  126. on isBelow me, v
  127.   return v > the bottom of sprite pTableChannel
  128. end
  129.  
  130. on isLeftOf me, h
  131.   return h <= the left of sprite pTableChannel
  132. end
  133.  
  134. on isRightOf me, h
  135.   return h > the right of sprite pTableChannel
  136. end
  137.  
  138. on getMouseCell me, h, v
  139.   if v <= (the top of sprite pTableChannel + 5) then
  140.     v = the top of sprite pTableChannel + 5
  141.   else
  142.     if v > (the bottom of sprite pTableChannel - 5) then
  143.       v = the bottom of sprite pTableChannel - 5
  144.     end if
  145.   end if
  146.   if h <= (the left of sprite pTableChannel + 5) then
  147.     h = the left of sprite pTableChannel + 5
  148.   else
  149.     if h > (the right of sprite pTableChannel - 5) then
  150.       h = the right of sprite pTableChannel - 5
  151.     end if
  152.   end if
  153.   return cellToPoint(me._me, pointToCell(sprite(pTableChannel), point(h, v)))
  154. end
  155.  
  156. on getVisRect me, theRect
  157.   R = rect(0, 0, 0, 0)
  158.   if not ((theRect.left > pVisRect.right) or (theRect.top > pVisRect.bottom) or (theRect.right < pVisRect.left) or (theRect.bottom < pVisRect.top)) then
  159.     R.left = max(theRect.left, pVisRect.left)
  160.     R.top = max(theRect.top, pVisRect.top)
  161.     R.right = min(theRect.right, pVisRect.right)
  162.     R.bottom = min(theRect.bottom, pVisRect.bottom)
  163.   end if
  164.   if R <> rect(0, 0, 0, 0) then
  165.     r1 = getCellRect(sprite(pTableChannel), point(getAt(R, 1), getAt(R, 2)))
  166.     r2 = getCellRect(sprite(pTableChannel), point(getAt(R, 3), getAt(R, 4)))
  167.     if not voidp(r1) and not voidp(r2) then
  168.       R = rect(r1.left, r1.top, r2.right, r2.bottom)
  169.     else
  170.       R = rect(0, 0, 0, 0)
  171.     end if
  172.   end if
  173.   return R
  174. end
  175.  
  176. on cellToPoint me, theCell
  177.   if (theCell mod pTable.columnCount) = 0 then
  178.     return point(pTable.columnCount, theCell / pTable.columnCount)
  179.   else
  180.     return point(theCell mod pTable.columnCount, (theCell / pTable.columnCount) + 1)
  181.   end if
  182. end
  183.  
  184. on getData me
  185.   return member(pTable).tableData
  186. end
  187.  
  188. on setData me, data
  189.   member(pTable).tableData = data
  190.   return me
  191. end
  192.  
  193. on getCellRect me, theCell
  194.   return getCellRect(sprite(pTableChannel), theCell)
  195. end
  196.  
  197. on isCellVisible me, theCellRect
  198.   return intersect(the rect of sprite pTableChannel, theCellRect) <> rect(0, 0, 0, 0)
  199. end
  200.  
  201. on isEditCellVisible me, theCell
  202.   h = getAt(theCell, 1)
  203.   v = getAt(theCell, 2)
  204.   return not ((h > pVisRect.right) or (v > pVisRect.bottom) or (h < pVisRect.left) or (v < pVisRect.top))
  205. end
  206.  
  207. on getCellContents me, theCell
  208.   cellRef = (pTable.columnCount * (getAt(theCell, 2) - 1)) + getAt(theCell, 1)
  209.   return getAt(member(pTable).tableData, cellRef)
  210. end
  211.  
  212. on setCellContents me, theCell, theContents
  213.   t = duplicate(member(pTable).tableData)
  214.   cellRef = (pTable.columnCount * (getAt(theCell, 2) - 1)) + getAt(theCell, 1)
  215.   oldContents = getAt(member(pTable).tableData, cellRef)
  216.   setAt(t, cellRef, theContents)
  217.   member(pTable).tableData = t
  218.   return me
  219. end
  220.  
  221. on getSelectedData me, theRect
  222.   data = duplicate(member(pTable).tableData)
  223.   selectedData = []
  224.   repeat with i = theRect.top to theRect.bottom
  225.     repeat with j = theRect.left to theRect.right
  226.       append(selectedData, getAt(data, ((i - 1) * pTable.columnCount) + j))
  227.     end repeat
  228.   end repeat
  229.   return selectedData
  230. end
  231.  
  232. on cutSelectedData me, theRect
  233.   data = duplicate(member(pTable).tableData)
  234.   selectedData = []
  235.   repeat with i = theRect.top to theRect.bottom
  236.     repeat with j = theRect.left to theRect.right
  237.       append(selectedData, getAt(data, ((i - 1) * pTable.columnCount) + j))
  238.       setAt(data, ((i - 1) * pTable.columnCount) + j, EMPTY)
  239.     end repeat
  240.   end repeat
  241.   member(pTable).tableData = data
  242.   return selectedData
  243. end
  244.  
  245. on setSelectedData me, theRect, data
  246.   numCols = theRect.right - theRect.left + 1
  247.   if theRect.right > pTable.columnCount then
  248.     c = pTable.columnCount
  249.   else
  250.     c = theRect.right
  251.   end if
  252.   numRows = theRect.bottom - theRect.top + 1
  253.   if theRect.bottom > pTable.rowCount then
  254.     R = pTable.rowCount
  255.   else
  256.     R = theRect.bottom
  257.   end if
  258.   newData = duplicate(member(pTable).tableData)
  259.   repeat with i = theRect.left to c
  260.     repeat with j = theRect.top to R
  261.       locInTableList = ((j - 1) * pTable.columnCount) + i
  262.       locInPasteList = ((j - theRect.top) * numCols) + (i - theRect.left + 1)
  263.       setAt(newData, locInTableList, getAt(data, locInPasteList))
  264.     end repeat
  265.   end repeat
  266.   member(pTable).tableData = newData
  267.   return me
  268. end
  269.